/**
 * Copyright (c) 2009  Collaborative Development Group, C.S. Dept., University of Bari
 *
 * All rights reserved. This program and the accompanying materials are made available under
 * the terms of the Eclipse Public License v1.0  which accompanies this distribution, and is 
 * available at http://www.eclipse.org/legal/epl-v10.html
 */
package it.uniba.di.cdg.penelope;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExecutableExtension;
import org.eclipse.core.runtime.IExecutableExtensionFactory;
import org.ops4j.peaberry.eclipse.GuiceExtensionFactory;

import com.google.inject.Injector;

/**
 * Helper for supporting Guice/Peaberry dependency injection for Eclipse items (views, editors, handlers, ...).
 * Any extension point that supports {@link IExecutableExtension} and {@link IExecutableExtensionFactory} can use
 * this class.
 * <br/>
 * Note that the current implementation simply wraps {@link GuiceExtensionFactory}.
 */
public abstract class AbstractEclipseExtensionFactory implements IExecutableExtensionFactory, IExecutableExtension {

	private Injector injector;
	
	// Create injector it.uniba.di.cdg.jtalk.PenelopeExtensionFactory
	private GuiceExtensionFactory guiceFactory = new GuiceExtensionFactory();
		
	/* (non-Javadoc)
	 * @see org.eclipse.core.runtime.IExecutableExtensionFactory#create()
	 */
	@Override
	public Object create() throws CoreException {
		return guiceFactory.create();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object)
	 */
	@Override
	public void setInitializationData( IConfigurationElement config, String propertyName, Object data )
			throws CoreException {
		guiceFactory.setInitializationData( config, propertyName, data );
	}

	/**
	 * @param injector the injector to set
	 */
	public void setInjector( Injector injector ) {
		this.injector = injector;
	}

	/**
	 * @return the injector
	 */
	public Injector getInjector() {
		return injector;
	}
}
